package com.chd.ledger_server.service.impl;

import com.chd.ledger_server.entity.ModelBasePoints;
import com.chd.ledger_server.dao.ModelBasePointsDao;
import com.chd.ledger_server.service.ModelBasePointsService;
import com.chd.ledger_server.domain.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基础热点表(ModelBasePoints)表服务实现类
 *
 * @author makejava
 * @since 2025-07-08 10:20:08
 */
@Service("modelBasePointsService")
public class ModelBasePointsServiceImpl implements ModelBasePointsService {
    @Resource
    private ModelBasePointsDao modelBasePointsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pointId 主键
     * @return 实例对象
     */
    @Override
    public ModelBasePoints queryById(Integer pointId) {
        return this.modelBasePointsDao.queryById(pointId);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo queryAllModelBasePointssByPage(PageDto pageDto) {
        //空值处理
        if (pageDto.getPage() == null || pageDto.getSize() == null) {
            pageDto.setPage(1);
            pageDto.setSize(10);
        }
        PageHelper.startPage(pageDto.getPage(), pageDto.getSize());
        List<ModelBasePoints> list = modelBasePointsDao.queryAll(pageDto.getModelBasePoints());
        PageInfo<ModelBasePoints> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param modelBasePoints 实例对象
     * @return 实例对象
     */
    @Override
    public ModelBasePoints insert(ModelBasePoints modelBasePoints) {
        this.modelBasePointsDao.insert(modelBasePoints);
        return modelBasePoints;
    }

    /**
     * 修改数据
     *
     * @param modelBasePoints 实例对象
     * @return 实例对象
     */
    @Override
    public ModelBasePoints update(ModelBasePoints modelBasePoints) {
        this.modelBasePointsDao.update(modelBasePoints);
        return this.queryById(modelBasePoints.getPointId());
    }

    /**
     * 通过主键删除数据
     *
     * @param pointId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pointId) {
        return this.modelBasePointsDao.deleteById(pointId) > 0;
    }
}
